import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref({
      username: '',
      token: '',
      userId: 0,
      avatar: '',
    })

    function setToken(token: string) {
      userInfo.value.token = token
    }

    function setUserInfo(data: any) {
      userInfo.value = data
    }

    return { userInfo, setToken, setUserInfo }
  },
  {
    persist: true,
  }
)
